package com.eesujie.xcs.service.impl;

import com.eesujie.xcs.common.BusinessException;
import com.eesujie.xcs.entity.po.UserPO;
import com.eesujie.xcs.mapper.UserMapper;
import com.eesujie.xcs.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eesujie.xcs.util.PojoUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author eesujie
 * @since 2023-04-18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements UserService {

    @Override
    public UserPO validUser(String username, String password) {
        var user = getBaseMapper().selectOneByLogin(username,
                DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8)));
        if (user == null)
            throw new BusinessException("账号或者密码错误");
        return user;
    }
}
